package com.xsr.controller;

import com.github.pagehelper.PageInfo;
import com.xsr.pojo.Goods;
import com.xsr.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project xiaomi
 * @date 2022/9/13 21:39
 */
@Controller
@RequestMapping("/goodsservlet")
public class GoodsServlet {
    @Autowired
    private GoodsService goodsService;
    @RequestMapping("/getGoodsListByTypeId")
    public  ModelAndView  show(Integer typeId, Integer pageNum, Integer pageSize, HttpSession httpSession){
        Integer id = (Integer)httpSession.getAttribute("typeId");
        if(id==null){
       id=typeId;
        }
        if(typeId==null){
            typeId=id;
        }
        if(pageNum==null){
            pageNum=1;
        }
        if(pageSize==null){
            pageSize=8;
        }
        System.out.println(pageNum+" "+pageSize+" "+typeId);
        ModelAndView modelAndView = new ModelAndView();

        PageInfo<Goods> goodsPageInfo= goodsService.findById(typeId,pageNum,pageSize);

        modelAndView.addObject("pageBean",goodsPageInfo);
        httpSession.setAttribute("typeId",typeId);
        modelAndView.setViewName("/goodsList");
        return modelAndView;

    }
}
